package com.thinkgem.jeesite.modules.qiniu.web;

/**
 * Created by Administrator on 2016-10-31.
 */

import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.dao.TbQiNiuMapper;
import com.thinkgem.jeesite.modules.sys.entity.TbQiNiuAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value = "${adminPath}/qiniu/upload")
public class QiniuTokenController extends BaseController {

    @Autowired
    private TbQiNiuMapper tbQiNiuMapper;

    @RequestMapping("/token")
    @ResponseBody
    public Token token(HttpServletResponse response) throws Exception {
        TbQiNiuAccount tbQiNiuAccount = new TbQiNiuAccount();
        tbQiNiuAccount.setType("H5");
        TbQiNiuAccount account = tbQiNiuMapper.selectByType(tbQiNiuAccount);
        QiniuToken uploadDemo = new QiniuToken();
        uploadDemo.setAccessKey(account.getAccessKey());
        uploadDemo.setSecretKey(account.getSecretKey());
        uploadDemo.setBucketName(account.getBucketName());
        uploadDemo.setDomain(account.getDomain());
        return new Token(uploadDemo.getUpToken());
     }
}
